Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#12048] Migrate tests for CalculateUsageStatisticsAction #13247

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

InfinityTwo
Copy link
Contributor

Part of #12048

Outline of Solution
Added the unit tests for CalculateUsageStatisticsAction for PostgreSQL.

Comment on lines +29 to +32
Instant endTime = TimeHelper.getInstantNearestHourBefore(Instant.now());
Instant startTime = endTime.minus(COLLECTION_TIME_PERIOD, ChronoUnit.MINUTES);
UsageStatistics testUsageStatistics;
UsageStatisticsAttributes testUsageStatisticsAttributes;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's make these attributes private for consistency

Comment on lines +86 to +95
testUsageStatistics = new UsageStatistics(
startTime,
COLLECTION_TIME_PERIOD,
NUMBER_OF_RESPONSES,
NUMBER_OF_COURSES,
NUMBER_OF_STUDENTS,
NUMBER_OF_INSTRUCTORS,
NUMBER_OF_ACCOUNT_REQUESTS,
0,
0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can create a getTypicalUsageStatistics() method in BaseTestCase.java with all of these values/attributes over there for extensibility.

Comment on lines +96 to +103
testUsageStatisticsAttributes =
UsageStatisticsAttributes.builder(startTime, COLLECTION_TIME_PERIOD)
.withNumResponses(NUMBER_OF_RESPONSES)
.withNumCourses(NUMBER_OF_COURSES)
.withNumStudents(NUMBER_OF_STUDENTS)
.withNumInstructors(NUMBER_OF_INSTRUCTORS)
.withNumAccountRequests(NUMBER_OF_ACCOUNT_REQUESTS)
.build();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In UsageStatisticsAttributes.java, there is a valueOf() method that takes in a teammates.storage.entity.UsageStatistics and creates a UsageStatisticsAttributes with the same attributes. It's quite similar to what we're trying to do here

I think we can create another valueOf (Overloading) for the SQL version of UsageStatistics. To resolve the class name conflicts, the new method's parameter type can be teammates.sqlstorage.entity.UsageStatistics (No need to import). The old method can remain.

@InfinityTwo Let me know what you think about this proposal!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the idea is great, but from what I saw the last time, the use of UsageStatisticsAttributes is only for the old datastore logic. I think once migration is completed, I believe the use for it becomes redundant and it solely uses UsageStatistics in the action, assuming we remember to change it after migration. Right now, it seems like it just concatenates both values together for the output.

I was thinking we could add a comment to remove it eventually but @jasonqiu212 what do you think? I'm cool with either ways.

@jasonqiu212 jasonqiu212 added the s.Ongoing The PR is being worked on by the author(s) label Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s.Ongoing The PR is being worked on by the author(s)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants